#include "time.h"
#include "stm32f10x_tim.h"
u8 i=0;
u8 all_buttom=0;
u8 all_close=0;
void time_init(u16 per,u16 psc){
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitstructure;
	NVIC_InitTypeDef NVIC_Initstructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
	TIM_TimeBaseInitstructure.TIM_Prescaler=psc;
	TIM_TimeBaseInitstructure.TIM_CounterMode=TIM_CounterMode_Up;
	TIM_TimeBaseInitstructure.TIM_Period=per;
	TIM_TimeBaseInitstructure.TIM_ClockDivision=TIM_CKD_DIV1;
	TIM_TimeBaseInit(TIM4,&TIM_TimeBaseInitstructure);
	TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
	TIM_Cmd(TIM4,ENABLE);
	TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
	NVIC_Initstructure.NVIC_IRQChannel=TIM4_IRQn;
	NVIC_Initstructure.NVIC_IRQChannelCmd=ENABLE;
	NVIC_Initstructure.NVIC_IRQChannelPreemptionPriority=2;
	NVIC_Initstructure.NVIC_IRQChannelSubPriority=3;
	NVIC_Init(&NVIC_Initstructure);
}
void TIM4_IRQHandler(void){
if(TIM_GetITStatus(TIM4,TIM_IT_Update)){
	mpu_dmp_get_data(&pitch,&roll,&yaw);
	if(i<2)i++;
	else {if(all_buttom)double_Fly_Task(0.03);
	i=0;}
	if(all_close)TIM_Cmd(TIM3,DISABLE);
}
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);




}

